#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexCurrency(L"(\\$|£)(\\d+((\\.|,)\\d+)*)");

// $XX	XX dollar(s)
void TextNormalizer::TnReCurrency(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while (regex_search(*fpInWsentence, tWsmatch, mcWregexCurrency))
	{
		string tStrCurrency = wstring2utf8string(tWsmatch[0]);		//匹配到的字符串
		StrReplace(tStrCurrency, ",", "");
		StrReplace(tStrCurrency, " ", "");

		const wstring tcWstrCurrency = utf8string2wstring(tStrCurrency);
		const wstring tcWstrSignal = tcWstrCurrency.substr(0, 1);
		const string tcStrNumber = wstring2utf8string( tcWstrCurrency.substr(1) );

		string tStrReplace = " ";
		tStrReplace += ReplaceMethod(vector<string>{tcStrNumber}, (fcInLanguage==LANG_EN)?RME_en_negative_decimal:RME_zh_negative_decimal);

		if(tcWstrSignal == L"$") {
			tStrReplace += (tcWstrCurrency==L"1") ? "dollar" : "dollars";
		}
		else if(tcWstrSignal == L"£") {
			tStrReplace += (tcWstrCurrency==L"1") ? "pound" : "pounds";
		}
		tStrReplace += " ";

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}
